﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Logic.ClarizenSvc;
using Logic;
using BLL;

namespace ClarizenGadget.Controllers
{
    public class ClarizenController : Controller
    {
        [HttpGet]
        public ActionResult Link(string link)
        {
            AppLoginMessage msg = new AppLoginMessage { };
            var res = (AppLoginResult)new QueryComponent().Execute(msg)[0];

            return Redirect(string.Format("{1}&targetUrl={0}", HttpUtility.UrlEncode(link), res.Url));
        }

        [HttpPost]
        public ActionResult GetLink(string link)
        {
            AppLoginMessage msg = new AppLoginMessage { };
            var res = (AppLoginResult)new QueryComponent().Execute(msg)[0];

            return Json(string.Format("{1}&targetUrl={0}", link, res.Url));
        }

        [HttpGet]
        public ActionResult Create()
        {
            ViewBag.IsAuthenticated = !string.IsNullOrEmpty(Users.GetGoogleID(useValidatedSig:false ,useSession: true));
            return View();
        }

        [HttpGet]
        public ActionResult AdminActivate()
        {
            return View();
        }
    }
}
